using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Simple.Contracts.Contracts;
using Simple.Contracts.Models;
using Simple.Contracts.Models.Common;
using Simple.Contracts.Models.Common.Page;
using Simple.WebAi.Authorizes;
using System.ComponentModel.DataAnnotations;

namespace Simple.WebAi.Controllers
{
    /// <summary>
    /// 公司管理控制器
    /// </summary>
    [Route("api/company")]
    [AccountAuthorize]
    [ApiController]
    public class CompanyController : ControllerBase
    {
        private readonly ICompanyService _companyService;

        /// <summary>
        /// 依赖注入
        /// </summary>
        /// <param name="companyService">公司服务</param>
        public CompanyController(ICompanyService companyService)
        {
            _companyService = companyService;
        }

        /// <summary>
        /// 获取公司列表（分页）
        /// </summary>
        /// <param name="input">公司列表查询参数</param>
        /// <returns>公司分页列表</returns>
        [HttpPost("list")]
        [AccountAuthorize]
        public async Task<Result<PageDto<CompanyDto>>> GetPageList(CompanyListInput input)
        {
            return await _companyService.GetPageList(input);
        }

        /// <summary>
        /// 保存公司信息
        /// </summary>
        /// <param name="input">公司保存参数</param>
        /// <returns>公司ID</returns>
        [HttpPost("save")]
        [AccountAuthorize]
        public async Task<Result<string>> Save(CompanySaveInput input)
        {
            return await _companyService.Save(input);
        }

        /// <summary>
        /// 修改公司版本
        /// </summary>
        /// <param name="input">修改版本参数</param>
        /// <returns>修改结果</returns>
        [HttpPost("update-version")]
        [AccountAuthorize]
        public async Task<Result<bool>> UpdateVersion(UpdateCompanyVersionInput input)
        {
            return await _companyService.UpdateVersion(input);
        }

        /// <summary>
        /// 修改公司过期时间
        /// </summary>
        /// <param name="input">修改过期时间参数</param>
        /// <returns>修改结果</returns>
        [HttpPost("update-expiry-time")]
        [AccountAuthorize]
        public async Task<Result<bool>> UpdateExpiryTime(UpdateCompanyExpiryTimeInput input)
        {
            return await _companyService.UpdateExpiryTime(input);
        }

        /// <summary>
        /// 删除公司
        /// </summary>
        /// <param name="companyId">公司ID</param>
        /// <returns>删除结果</returns>
        [HttpPost("delete")]
        [AccountAuthorize]
        public async Task<Result<bool>> Delete([Required][FromQuery] long companyId)
        {
            return await _companyService.Delete(companyId);
        }
    }
}